home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / Snippets / Testing & Debugging / Audit / Src / DisplayAudit.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-21  |  9.5 KB  |  362 lines  |  [TEXT/KAHL]

  1. /*                                    DisplayAudit.h                                */
  2. /*
  3.  * DisplayAudit.c
  4.  * Copyright © 1992-93, Apple Computer Inc. All Rights Reserved.
  5.  * Programmed by Martin Minow,
  6.  *    Internet:    minow@apple.com
  7.  *    AppleLink:    MINOW
  8.  * Version of January 22, 1993
  9.  *
  10.  * Edit History
  11.  *    93.01.09 MM        First public release
  12.  *    93.01.22 MM        Broke out from DisplayAudit.c
  13.  *    93.07.09 MM        Replaced simple text window by Log Manager and many other
  14.  *                    major revisions.
  15.  */
  16. /*
  17.  * Resource definitions
  18.  */
  19. #define ALRT_NonFatal        9000
  20. #define ALRT_Fatal            9001
  21. #define MBAR_MenuBar        1
  22. #define MENU_Apple            1
  23. #define MENU_File            256
  24. #define    MENU_Edit            257
  25. #define MENU_Font            258
  26. #define MENU_FontSize        259
  27. #define CNTL_FontPopup        256
  28. #define CNTL_SizePopup        257
  29. #define WIND_Document        256
  30. #define DLOG_SFPutFile        4000
  31. #define STRN_Messages        128        /* Error messages                            */
  32. #define STRN_Strings        129        /* Random text strings                        */
  33. #define STR_FinderString    128        /* Finder info string for param file        */
  34. /*
  35.  * Preference resource file information.
  36.  * kApplicationCreator    is the registered Application Creator ID.
  37.  * kDefaultAuditIdent    is the registered Application Creator ID for the sample
  38.  *                        CSAM - I used this because it's convenient (and that's
  39.  *                        what I'm debugging).
  40.  */
  41. #define kApplicationCreator        'MAM1'        /* Registered application creator    */
  42. #define kDefaultAuditIdent        'Pdsm'        /* kDSAMCreatorID                    */
  43. #define kPreferenceFileType        'pref'        /* Preference fileType                */
  44. #define PARM_ResourceID            1024        /* We'll create this resource        */
  45. #define STR_FinderIDString        (-16397)    /* Resource id of help message        */
  46. #define kNoParamFile            (-1)        /* Signal no parameter file created    */
  47. #define kDefaultAuditRecords    128            /* How many audit records to make    */
  48. #define kDefaultDisplayLines    512            /* How many lines to keep in memory    */
  49. #define kMinWindowWidth            64            /* Minimum width in pixels            */
  50. #define kMinWindowHeight        64            /* Minimum height in pixels            */
  51. #define kScrollBarWidth            16
  52. #define kScrollBarOffset        (kScrollBarWidth - 1)
  53. #ifndef REZ
  54. #ifndef THINK_C
  55. #include <Errors.h>
  56. #include <Finder.h>
  57. #include <Folders.h>
  58. #include <Script.h>
  59. #include <Types.h>
  60. #include <Resources.h>
  61. #include <QuickDraw.h>
  62. #include <Fonts.h>
  63. #include <Events.h>
  64. #include <Windows.h>
  65. #include <Menus.h>
  66. #include <TextEdit.h>
  67. #include <Dialogs.h>
  68. #include <Desk.h>
  69. #include <ToolUtils.h>
  70. #include <Memory.h>
  71. #include <Files.h>
  72. #include <OSUtils.h>
  73. #include <OSEvents.h>
  74. #include <DiskInit.h>
  75. #include <Traps.h>
  76. #endif
  77. #include <GestaltEqu.h>
  78. #include <Packages.h>
  79. #include <Processes.h>
  80. #include "Audit.h"
  81. #include "Failure.h"
  82. #include "LogManager.h"
  83.  
  84. #ifndef TRUE
  85. #define TRUE        1
  86. #define FALSE        0
  87. #endif
  88. #ifndef EXTERN
  89. #define EXTERN        extern        /* Not in main program    */
  90. #endif
  91.  
  92. /*
  93.  * These are the "SleepTime" parameters for WaitNextEvent. The idea is that we
  94.  * sleep for a long time if we're in the background; for a short time if active.
  95.  */
  96. #define kForegroundTicks        6
  97. #define kBackgroundTicks        60
  98.  
  99. enum AppleMenu {
  100.     kAppleAbout            = 1
  101. };
  102.  
  103. enum FileMenu {
  104.     kFileNewWindow        = 1,
  105.     kFileCloseWindow,
  106.     kFileUnused1,
  107.     kFileSaveAs,
  108.     kFileCloseFile,
  109.     kFileUnused2,
  110.     kFileQuit
  111. };
  112.  
  113. enum EditMenu {
  114.     kEditUndo            = 1,
  115.     kEditUnused,
  116.     kEditCut,
  117.     kEditCopy,
  118.     kEditPaste,
  119.     kEditClear
  120. };
  121.  
  122. /*
  123.  * Error alert messages. These are in resource (STR# STRN_Messages)
  124.  */
  125. enum {
  126.     kNoMessage                    = 0,
  127.     kErrInitialization,
  128.     kErrNoMemory,
  129.     kErrCreateAuditRecord,
  130.     kErrCreateTextWindow,
  131.     kErrSystemVersion,
  132.     kErrFindPreferenceFolder,
  133.     kErrFindPreferenceFile,
  134.     kErrOpenPreferenceFile,
  135.     kErrCreatePreferenceFile,
  136.     kErrWritePreferenceResource,
  137.     kErrReadPreferenceResource,
  138.     kErrCreateOutputFile,
  139.     kErrWriteOutputFile,
  140.     kErrCloseOutputFile,
  141.     kDummyLastMessage
  142. };
  143.     
  144. /*
  145.  * Random text messages. These are in resource ('STR#' STRN_Strings)
  146.  */
  147. enum {
  148.     kAuditParameterFileName        = 1,
  149.     
  150.     kDummyLastString
  151. };
  152.  
  153. /*
  154.  * This is the content of the Preferences file.
  155.  */
  156. typedef struct Parameters {
  157.     OSType                auditIdent;            /* Default Audit ident                */
  158.     long                enableAudit;        /* TRUE to start auditing            */
  159.     long                auditRecords;        /* Number of audit records             */
  160.     long                logDisplayLines;    /* Number of display lines            */
  161.     long                fontSize;            /* Font height in pixels            */
  162.     Str255                fontName;            /* User's chosen font                */
  163. } Parameters;
  164.  
  165. /*
  166.  * All document-specific variables are in this structure. This allows us to
  167.  * extend DisplayAudit so one application can watch several Audit Records.
  168.  */
  169. typedef struct DocumentRecord {
  170.     WindowRecord    windowRecord;            /* In this window - must be first    */
  171.     ListHandle        logListHandle;            /* Display log                        */
  172.     OSType            auditIdent;                /* Watching this audit record        */
  173.     AuditPtr        auditPtr;                /* Really atching this audit record    */
  174.     AuditEntry        currentAuditEntry;        /* Working on this one                */
  175.     short            scanCount;                /* Equals number of Audit Records    */
  176.     unsigned long    totalMissedCount;        /* Total number of missed records    */
  177.     unsigned long    logIndex;                /* Current record being displayed    */
  178.     Boolean            enableAudit;            /* TRUE if auditing enabled            */
  179.     ProcessSerialNumber    oldPSN;                /* Previous DisplayAudit Process    */
  180.     short            logFileRefNum;            /* Writing to this file if non-zero    */
  181.     short            logFileVRefNum;            /* Writing to this volume            */
  182.     Str63            logFileName;            /* Writing to this named file        */
  183. } DocumentRecord, *DocumentPtr;
  184. /*
  185.  * All functions have a "documentPtr" parameter.
  186.  */
  187. #define DOC            (*documentPtr)
  188. #define WINDOW_PTR    ((WindowPtr) &DOC.windowRecord)
  189. #define WINDOW        (*WINDOW_PTR)
  190. #define ENTRY        (DOC.currentAuditEntry)
  191. #define IsOurWindow(theWindow) (                                \
  192.         (theWindow) != NULL                                        \
  193.         && ((WindowPeek) (theWindow))->windowKind == userKind    \
  194.     )
  195. /*
  196.  * AuditDocument.c: DisplayAudit Document Management
  197.  */
  198. void                                MakeDocumentWindow(void);
  199. void                                ProcessAuditDocument(
  200.         register DocumentPtr            documentPtr
  201.     );
  202. void                                ProcessAuditEntry(
  203.         register DocumentPtr            documentPtr
  204.     );
  205. void                                DoWindowKeyDown(
  206.         register DocumentPtr            documentPtr
  207.     );
  208. void                                DoContentClick(
  209.         register DocumentPtr            documentPtr
  210.     );
  211. void                                UpdateDocumentWindow(
  212.         register DocumentPtr            documentPtr
  213.     );
  214. void                                ActivateDocumentWindow(
  215.         register DocumentPtr            documentPtr,
  216.         Boolean                            isActivating
  217.     );
  218. void                                DisposeDocumentWindow(
  219.         register DocumentPtr            documentPtr
  220.     );
  221. void                                DecorateWindow(
  222.         register DocumentPtr            documentPtr
  223.     );
  224. void                                DoDocumentSaveAs(
  225.         register DocumentPtr            documentPtr
  226.     );
  227. void                                DoDocumentCloseFile(
  228.         register DocumentPtr            documentPtr
  229.     );
  230.  
  231. /*
  232.  * WindowUtilities.c
  233.  */
  234. Boolean                                DoGrowWindow(
  235.         register WindowPtr                theWindow,
  236.         short                            minWindowWidth,
  237.         short                            minWindowHeight
  238.     );
  239. void                                DoZoomWindow(
  240.         register WindowPtr                theWindow,
  241.         short                            whichPart
  242.     );
  243. /*
  244.  * AuditFileDialog.c
  245.  */
  246. void                                AuditFileDialog(
  247.         short                            dialogID,
  248.         ConstStr255Param                promptString,
  249.         ConstStr255Param                originalName,
  250.         SFReply                            *reply
  251.     );
  252.  
  253. /*
  254.  * DisplayAuditFile.c
  255.  */
  256. /*
  257.  * File functions
  258.  */
  259. void                                PromptAndCreateAuditOutputFile(
  260.         ConstStr255Param                promptString,
  261.         ConstStr255Param                defaultFileName,
  262.         OSType                            creator,
  263.         short                            *fileRefNum,
  264.         short                            *volumeRefNum,
  265.         Str63                            fileName
  266.     );
  267. OSErr                                CreateOutputFile(
  268.         OSType                            creator,
  269.         ConstStr255Param                fileName,
  270.         short                            vRefNum,
  271.         short                            *fileRefNum
  272.     );
  273. void                                WriteAuditOutputLine(
  274.         ConstStr255Param                theText,
  275.         short                            fileRefNum
  276.     );
  277. void                                CloseAuditOutputFile(
  278.         OSErr                            status,
  279.         short                            fileRefNum,
  280.         short                            volumeRefNum,
  281.         ConstStr255Param                fileName
  282.     );
  283.  
  284. /*
  285.  * DisplayAuditPreferences.c
  286.  */
  287. void                                OpenAuditParameterFile(void);
  288. void                                ReadAuditParameters(void);
  289. void                                WriteAuditParameters(void);
  290. void                                ParameterFactorySettings(void);
  291. OSErr                                SearchForCreatorType(
  292.         short                            prefVRefNum,
  293.         long                            prefDirID,
  294.         Str63                            trueFileName
  295.     );
  296.  
  297. void                                ErrorAlert(
  298.         OSErr                            status,
  299.         short                            messageIndex,
  300.         Boolean                            fatal
  301.     );
  302.  
  303. #define height(box)                (box.bottom - box.top)
  304. #define width(box)                (box.right - box.left)
  305. /*
  306.  * Cheap 'n dirty pascal string copy routine.
  307.  */
  308. #define pstrcpy(dst, src) do {                            \
  309.         StringPtr    _src = (src);                        \
  310.         BlockMove(_src, dst, _src[0] + 1);                \
  311.     } while (0)
  312. /*
  313.  * Cheap 'n dirty pascal string concat.
  314.  */
  315. #define pstrcat(dst, src) do {                            \
  316.         StringPtr        _dst = (dst);                    \
  317.         StringPtr        _src = (src);                    \
  318.         short            _len;                            \
  319.         _len = 255 - _dst[0];                            \
  320.         if (_len > _src[0]) _len = _src[0];                \
  321.         BlockMove(&_src[1], &_dst[1] + _dst[0], _len);    \
  322.         _dst[0] += _len;                                \
  323.     } while (0)
  324. /*
  325.  * Cheap 'n dirty memory clear routine.
  326.  */
  327. #define CLEAR(record) do {                                \
  328.         register char    *ptr = (char *) &record;        \
  329.         register long    size;                            \
  330.         for (size = sizeof record; size > 0; --size)    \
  331.             *ptr++ = 0;                                    \
  332.     } while (0)
  333.  
  334. /*
  335.  * Globals
  336.  */
  337. EXTERN EventRecord            gEventRecord;
  338. #define    EVENT                (gEventRecord)
  339. EXTERN Parameters            gParameterRecord;
  340. #define PARM                (gParameterRecord)
  341. EXTERN short                gParameterFileRefNum;
  342. EXTERN short                gOpenWindowCount;
  343. EXTERN Boolean                gInForeground;
  344. EXTERN Boolean                gParameterUpdateNeeded;
  345. EXTERN Boolean                gUpdateMenusNeeded;
  346. EXTERN short                gWindowOffset;
  347. EXTERN Boolean                gHasColorQuickDraw;
  348. /*
  349.  * We only want to set the old PSN once. Otherwise, there's a risk of garbling
  350.  * the Audit PSN if the user closes windows in a different order.
  351.  */
  352. EXTERN Boolean                gHaveOldPSN;            /* gOldPSN set already        */
  353. EXTERN ProcessSerialNumber    gMyPSN;
  354. EXTERN Boolean                gQuitNow;
  355. EXTERN MenuHandle            gAppleMenu;
  356. EXTERN MenuHandle            gFileMenu;
  357. EXTERN MenuHandle            gEditMenu;
  358. EXTERN MenuHandle            gFontMenu;
  359. EXTERN MenuHandle            gFontSizeMenu;
  360.  
  361. #endif /* REZ */
  362.